package com.ithanwen.controller;

import com.ithanwen.pojo.Result;
import com.ithanwen.pojo.Student;
import com.ithanwen.pojo.StudentQueryParam;
import com.ithanwen.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created By tony
 * <br/>Date: 2025/7/14 16:58
 * <br/>Description:
 */
@RestController
public class StudentController {

        @Autowired
        private StudentService studentService;
        //分页查询
        @RequestMapping(value = "/students",method = RequestMethod.GET)
        public Result list(StudentQueryParam studentQueryParam){
                return Result.success(studentService.page(studentQueryParam));
        }

        @RequestMapping(value = "/students/{ids}",method = RequestMethod.DELETE)
        public Result deleteStudent(@PathVariable("ids") List<Integer> ids){
                studentService.deleteByIds(ids);
                return Result.success();
        }

        @RequestMapping(value = "/students",method = RequestMethod.POST)
        public Result addStudent(@RequestBody Student student){
                studentService.add(student);
                return Result.success();
        }

        @RequestMapping(value = "/students/{id}",method = RequestMethod.GET)
        public Result getStudentById(@PathVariable("id") Integer id){
                return Result.success(studentService.findById(id));
        }
        @RequestMapping(value = "/students",method = RequestMethod.PUT)
        public Result updateStudent(@RequestBody Student student){
                studentService.update(student);
                return Result.success();
        }

        @RequestMapping(value = "/students/violation/{id}/{score}",method = RequestMethod.PUT)
        public Result updateStudentViolation(@PathVariable("id") Integer id,@PathVariable("score") Short score){
                studentService.updateViolation(id,score);
                return Result.success();
        }
}
